/**
 * Created by morefun on 2017/6/17.
 */
var InputStrategy = function () {
  let strategy = {
    notNull: function (value) {
      return /\s+/.test(value) ? '请输入内容' : ''
    },
    number: function (value) {
      return /^[0-9]+(\.[0-9]+)?$/.test(value) ? '' : '请输入数字'
    },
    phone: function (value) {
      return /^\d{3}\-\d{8}$|^\d{4}\-\d{7}$/.test(value) ? '' : '请输入正确的电话格式，如：010-12345678 或 0418-1234567'
    }
  }
  return {
    check: function (type, value) {
      value = value.replace(/^\s+|\s+$/g, '')
      return strategy[type] ? strategy[type](value) : '没有该类型的检测方法'
    },
    addStrategy: function (type, fn) {
      strategy[type] = fn
    }
  }
}

function currying(fn) {
  const Slice = [].slice
  let args = Slice.call(arguments,1);
  return function () {
    let addArgs = Slice.call(arguments),
      allArgs = args.concat(addArgs)
    return fn.apply(null,allArgs)
  }
}

//同步模块模式
let F = F || {}

// @param str 模块路由
// @param fb 模块方法
F.define = function (str, fn) {

  let parts = str.split('.'),
    old = parent = this,
    i = len = 0;

  if(parts[0] === 'F'){
    parts = parts.slice(1);
  }

  for(len = parts.length; i < len; i++){
    if(typeof parent[parts[i]] === 'undefined'){
      parent[parts[i]] = {};
    }
    old = parent;
    parent = parent[parts[i]];
  }

  if(fn){
    old[parts[--i]] = fn();
  }

  return this
}

F.define('string', function () {
  return {
    trim : function (str) {
      return str.replace(/^\s+|\s+$/g, '');
    }
  }
})

F.define('dom', function () {
  let $ = function (id) {
    $.dom = document.getElementById(id)
    return $
  }

  $.html = function (html) {
    if(html){
      this.dom.innerHTML = html;
      return this
    }else{
      return this.dom.innerHTML;
    }
  }
  return $;
})
